﻿Imports System.Data.OleDb
Imports System.Xml
Imports System.ServiceModel.Syndication



Public Class releaseRSS
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        Response.Clear()
        Response.ContentType = "application/rss+xml"
        Dim xml As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        xml.WriteStartDocument()
        xml.WriteStartElement("rss")
        xml.WriteAttributeString("version", "2.0")
        xml.WriteStartElement("channel")

        Dim conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("godzillaFilms").ConnectionString)
        Dim cmd As New OleDbCommand("SELECT * FROM godzillaFilmsQuery", conn)
        cmd.Connection.Open()
        Dim dr As OleDbDataReader = cmd.ExecuteReader()


        xml.WriteElementString("title", "Godzilla home video releases")
        xml.WriteElementString("link", okURL("releaseList.aspx"))
        xml.WriteElementString("description", "This feed shows the current godzilla home video releases")
        xml.WriteElementString("language", "en-us")
        xml.WriteElementString("ttl", "60")

        Do While dr.Read()
            Dim desc As String = "Format: " & dr("Format").ToString() & ", " & "Region: " & dr("Region").ToString()
            xml.WriteStartElement("item")
            xml.WriteElementString("title", dr("filmName").ToString())
            xml.WriteElementString("link", okURL("releaseDetail.aspx?ID=") & dr("ID").ToString())
            xml.WriteStartElement("guid")
            xml.WriteAttributeString("isPermaLink", "true")
            xml.WriteString(okURL("releaseDetail.aspx?ID=") & dr("ID").ToString())
            xml.WriteEndElement()
            xml.WriteElementString("description", desc)
            xml.WriteEndElement()
        Loop

        xml.WriteEndElement()
        xml.WriteEndDocument()
        xml.Flush()
        xml.Close()
        Response.End()
    End Sub

    Private Function okURL(ByVal urlStr As String)
        Return Request.Url.GetLeftPart(UriPartial.Authority) & ResolveUrl(urlStr)
    End Function

End Class